﻿using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Ninject;
using StoryCardLogic.ImportExportData;

namespace StoryCardLogic.Test
{
    [TestClass]
    public class StoryTestLoadSave
    {
        //Bad Save
        //Bad Load


        [TestMethod]
        public void XmlSaveLoadStory()
        {
            IKernel kernel = new StandardKernel();
            kernel.Bind<IFile>().To<MyFile>();
            kernel.Bind<IStoryManager>().To<SampleStoryManager>();
            var storySaver = kernel.Get<XmlStorySaver>();
            storySaver.Save("c:/file/1.txt");
            var storyLoader = kernel.Get<XmlStoryLoader>();
            var stories = storyLoader.Load("c:/file/1.txt");

            Assert.AreEqual(stories.Count, 3);
            Assert.AreEqual(storyLoader.StoryManager.Stories.Count, stories.Count);
        }

        [TestMethod]
        public void TxtSaveLoadStory()
        {
            IKernel kernel = new StandardKernel();
            kernel.Bind<IFile>().To<MyFile>();
            kernel.Bind<IStoryManager>().To<SampleStoryManager>();

            //save
            var storySaver = kernel.Get<TxtStorySaver>();
            storySaver.Save("c:/file/1.txt");

            //load
            var storyLoader = kernel.Get<TxtStoryLoader>();
            var stories = storyLoader.Load("c:/file/1.txt");
            Assert.AreEqual(stories.Count, 3);
        }

        [TestMethod]
        public void StoryMerge()
        {
            var manager1 = new StoryManager();
            manager1.AddStory("story1");
            manager1.AddStory("story2");

            var manager2 = new StoryManager();
            manager2.AddStory("story6");

            manager1.AddStories(manager2);

            Assert.AreEqual(manager1.Stories.Count, 3);
            Assert.AreEqual(manager1.Stories[2].Text, "story6");
        }

        [TestMethod]
        public void StoryAddNull()
        {
            var manager = new StoryManager();
            Story story = null;
            manager.AddStory(story);
            manager.AddStory("");
            manager.AddStory("    ");
            Assert.AreEqual(manager.Stories.Count, 0);
        }
    }
}